package com.heyqing.topic.PostorderTraversal_0145;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * ClassName:PostorderTraversal
 * Package:com.heyqing.topic.PostorderTraversal_0145
 * Description:
 *
 * @Date:2024/9/17
 * @Author:Heyqing
 */
public class PostorderTraversal {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        achieveFunc(root, res);
        return res;
    }

    private void achieveFunc(TreeNode root, List<Integer> res) {
        if (Objects.isNull(root)) return;
        achieveFunc(root.left, res);
        achieveFunc(root.right, res);
        res.add(root.val);
    }
}
